package com.teach;

import java.time.LocalDate;
import java.util.Scanner;

/**
 * <pre>
 * - 万年历
 * Author : J.L.Zhou
 * E-Mail : 2233875735@qq.com
 * Tel : 151 1104 7708
 * Date : 2021-4-16 13:53:56
 * Version : 1.0
 * Copyright 2021 jlzhou.top Inc. All rights reserved.
 * Warning: this content is only for internal circulation of the company.
 *          It is forbidden to divulge it or use it for other commercial purposes.
 * </pre>
 *
 */
public class Demo04 {

	public static void main(String[] args) {
//		Scanner sc = new Scanner(System.in);
//		System.out.println("请输入年月");
//		int y = sc.nextInt();
//		int m = sc.nextInt();
//		printCalendar(y, m);
		for(int i=1;i<=12;i++) {
			printCalendar(2021, i);
			printCalendar1(2021, i);
		}

	}

	public static void printCalendar1(int y, int m) {
		LocalDate date = LocalDate.of(y, m, 1);
//		System.out.println(date);
		int w = date.getDayOfWeek().getValue();// 1-7 周一-周日
//		System.out.println(w);
		int maxDate = date.plusMonths(1).minusDays(1).getDayOfMonth();
//		System.out.println(maxDate);
		System.out.println();
		System.out.println("\t" + y + "年" + m + "月");
		System.out.println("一\t二\t三\t四\t五\t六\t日");
		for(int i=0;i<w-1;i++) {
			System.out.print("\t");
		}
		for (int i = 1; i <= maxDate; i++) {
			System.out.print(i+"\t");
			if((i+w-1)%7==0) {
				System.out.println();
			}
		}
	}
	
	public static void printCalendar(int y, int m) {
		LocalDate date = LocalDate.of(y, m, 1);
		System.out.println();
		System.out.println("\t" + y + "年" + m + "月");
		System.out.println("日\t一\t二\t三\t四\t五\t六");
		int w = date.getDayOfWeek().getValue();//1-7 周一-周日
		for(int i=0;i<w&&w!=7;i++) {
			System.out.print("\t");
		}
		while(date.getMonthValue()==m) {
			System.out.print(date.getDayOfMonth()+"\t");
			
			if(date.getDayOfWeek().getValue()==6) {
				System.out.println();
			}
			
			date = date.plusDays(1);
		}
		
	}

}
